class Solution(object):
    def minCost(self, startPos, homePos, rowCosts, colCosts):
        ans = 0
        if startPos[0] < homePos[0]:
            for i in range(startPos[0] + 1, homePos[0] + 1):
                ans += rowCosts[i]
        if startPos[0] > homePos[0]:
            for i in range(startPos[0] - 1, homePos[0] - 1, -1):
                ans += rowCosts[i]
        if startPos[1] < homePos[1]:
            for i in range(startPos[1] + 1, homePos[1] + 1):
                ans += colCosts[i]
        if startPos[1] > homePos[1]:
            for i in range(startPos[1] - 1, homePos[1] - 1, -1):
                ans += colCosts[i]
        return ans
